const path = require('path')

const os = require('os');

// 获取本机IP
const myHost = (() => {
  var interfaces = os.networkInterfaces();
  for (var devName in interfaces) {
    var iface = interfaces[devName];
    for (var i = 0; i < iface.length; i++) {
      var alias = iface[i];
      if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
        return alias.address;
      }
    }
  }
})();

const myPort = 8000;

export default {
  mode: 'universal',
  server: {
    port: myPort, // default: 3000
    host: myHost // default: localhost
  },
  /*
   ** Headers of the page
   */
  head: {
    title: process.env.npm_package_name || '',
    meta: [{
        charset: 'utf-8'
      },
      {
        name: 'viewport',
        content: 'width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no'
      },
      {
        hid: 'description',
        name: 'description',
        content: process.env.npm_package_description || ''
      }
    ],
    link: [{
      rel: 'icon',
      type: 'image/x-icon',
      href: '/favicon.ico'
    }],
    script: [{
      src: '/js/common/flexible.js',
      type: 'text/javascript',
      charset: 'utf-8'
    }]
  },
  /*
   ** Customize the progress-bar color
   */
  loading: {
    color: '#fff'
  },
  /*
   ** Global CSS
   */
  css: [ //2.0开始  assets 只能用~assets这个路径  不能使用~/ 或者@/
    {
      src: "~assets/style/scss/common/reset.scss",
      lang: 'scss'
    },
    'mint-ui/lib/style.css'
  ],
  /*
   ** Plugins to load before mounting the App
   * 同时nuxt还支持区分只在浏览器中运行和只在服务端运行的插件
   * 只在浏览器运行：配置nuxt.config.js中plugins字段，将引入的插件属性设置为ssr： false
   * 只在服务端运行：直接在webpack打包server.bundle.js文件中，将process.SERVER_BUILD设置为true即可
   */
  plugins: [
    '@/plugins/global-components',
    '@/plugins/axios',
    {
      src: "~plugins/mint-ui",
      ssr: true
    },
    {
      src: "~plugins/default-passive-events",
      ssr: true
    },
    // {
    //   src: '~plugins/mockjs',
    //   ssr: false
    // },
    // {
    //   src: "~/plugins/vconsole",
    //   ssr: false
    // }
  ],
  /*
   ** Nuxt.js dev-modules
   */
  buildModules: [],
  /*
   ** Nuxt.js modules
   */
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/proxy'
  ],
  // axios: {
  //   proxy: true
  // },
  // proxy: [
  //   // 转发请求模拟数据
  //   [
  //     '/mock/',
  //     {
  //       target: `http://${myHost}:${myPort}`,
  //     }
  //   ]
  // ],
  /*
   ** Build configuration
   */
  build: {
    // analyze: true,
    vendor: ['axios', 'mint-ui', 'mockjs'],
    // 2.0开始 postcss 以后需要用 对象声明 ，不再支持数组方式。
    postcss: {
      plugins: {
        'postcss-px2rem': {
          remUnit: 75,
          exclude: '/node_modules|vant/'
        }
      },
      preset: {
        // 更改postcss-preset-env 设置
        autoprefixer: {
          grid: true
        }
      }
    },
    maxChunkSize: 300000,
    /*
     ** You can extend webpack config here
     */
    extend(config, ctx) {}
  }
}
